package com.funtl.itoken.common.dto;

import lombok.Data;

import java.io.Serializable;
import java.util.List;

@Data
public class BaseResult implements Serializable {
    private static final String RESULT_OK="createResult";
    private  static final String RESULT_NOT_OK="not_ok";
    private  static final String SUCCESS="成功操作";

    private static final long serialVersionUID = 1L;
    private String result;
    private Object data;
    private Cursor cursor;
    private String success;
    private List<Error> errors;

    public static BaseResult ok(String success){
        return createResult(RESULT_OK,null,null,success,null);
    }

    public static BaseResult ok(Object data){
        return createResult(RESULT_OK,data,null,SUCCESS,null);
    }

    public static BaseResult ok(){
        return createResult(RESULT_OK,null,null,SUCCESS,null);
    }

    public static BaseResult notOk(List<Error> errors){
        return createResult(RESULT_NOT_OK,null,null,"",errors);
    }

    public static BaseResult createResult(String result, Object data, Cursor cursor, String success, List<Error> errors){
        BaseResult baseResult = new BaseResult();
        baseResult.setResult(result);
        baseResult.setData(data);
        baseResult.setCursor(cursor);
        baseResult.setSuccess(success);
        baseResult.setErrors(errors);
        return baseResult;
    }

    public static BaseResult ok(List list, Cursor cursor) {
        return createResult(RESULT_OK,list,cursor,SUCCESS,null);
    }

    @Data
    public static class Cursor {
        private int total;
        private int offset;
        private int limit;
    }

    @Data
    public static class Error  implements Serializable{
        private static final long serialVersionUID = 1L;
        private String message;
        private String field;
    }

}
